package org.supper.user.controller;


import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.supper.common.util.CommonUtil;
import org.supper.common.util.UserUtil;
import org.supper.common.util.excel.ExcelUtil;
import org.supper.user.feign.TestFeign;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;


/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author huqi
 * @since 2021-04-17
 */
@Api(value = "用户模块", tags = "用户模块")
@RestController
@RequestMapping("/user")
public class UserController {
    @Resource
    TestFeign testFeign;
//    @Autowired
//    private UserService userService;
//
//    @PostMapping("/getUserName")
//    public UserEntity getUserName(@RequestParam(value = "userName") String userName) {
//        UserEntity user = userService.getOne(new QueryWrapper<UserEntity>().eq(UserEntity.USERNAME, userName)
//                .eq(UserEntity.DATA_ACTIVE, 0));
//        return user;
//    }
    @ApiOperation(value = "登录模块",notes = "登录")
    @GetMapping("/login")
    public String login() {
        String e = testFeign.getTest();
        return e;
    }
    @ApiOperation(value = "获取用户数据",notes = "获取用户数据")
    @GetMapping(value = "getRes")
    public Object getResponse() {
        return UserUtil.getUserData().getUsername();
    }


    @PostMapping("/excelDownLoad")
    public Object excelDownload(HttpServletResponse response){
        List<String> headerList = CommonUtil.getExcelHeaderList(UserTest.class);
        List<UserTest> auths = new ArrayList<>();
        for(int i = 0;i<100000;i++){
            UserTest auth = new UserTest();
           auth.setId(String.valueOf(i));
           auth.setUsername("huqi");
           auth.setPassword("mima");
            auths.add(auth);
        }
        ExcelUtil.downloadExcelFile("ceshi",headerList,auths,response);
        return null;
    }
}

